package com.bookstore.client.product.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bookstore.client.product.dao.IProductDao;
import com.bookstore.client.product.service.IProductService;
import com.bookstore.commons.beans.Notice;
import com.bookstore.commons.beans.Product;
import com.bookstore.utils.PageModel;

@Service
public class ProductServiceImpl implements IProductService {

	@Autowired
	private IProductDao productDao;
	
	@Override
	public List<Product> findProductByCategory(String category, PageModel pageModel) {

		Map<String,Object> map = new HashMap<>();
		map.put("category",category );
		map.put("start",pageModel.getFirstLimitParam() );
		map.put("size", pageModel.getPageSize());
		 
		
		return productDao.selectProductByCategory(map);
	}

	@Override
	public int findProductByCategoryCount(String category) {
		return productDao.selectProductByCategoryCount(category);
	}

	@Override
	public int findProductByNameCount(String name) {
		
		return productDao.selectProductByNameCount(name);
	}

	@Override
	public List<Product> findProductByName(String name, PageModel pageModel) {
		Map<String,Object> map = new HashMap<>();
		map.put("name",name);
		map.put("start",pageModel.getFirstLimitParam() );
		map.put("size", pageModel.getPageSize());
		 
		return productDao.selectProductByName(map);
	}

	@Override
	public Product findProductById(String id) {
		return productDao.selectProductById(id);
	}

	@Override
	public Notice findRecentNotice() {
		return productDao.selectRecentNotice();
	}

	@Override
	public List<Product> findWeekHostProduct() {
		return productDao.selectWeekHostProduct();
	}

}
